/**
 * 增加称重磅
 */
import {  Form, Input, message, Modal } from "antd"
import { FC } from "react"
import { postGbSystemSetAddPound } from "../../api"
import { useWindowFontSize } from "../../../../../assets/fun/Antd/configprovider"

const AddWeight:FC<{
    oneShow:boolean
    handleCallBack:() => void
    }> = ({
        oneShow,handleCallBack
    })=>{
    const [form] = Form.useForm();

    //限重设置的确定回调
    const handleOk = async () => {
        const values = await form.validateFields()
        const params = {
            ...values,
        }
        const { code, msg } = (await postGbSystemSetAddPound(params)) as {
            code: number
            msg: string
        }
        if (code === 20000) {
            message.success("增加成功")
            handleCallBack()
            form.resetFields()
        } else {
            message.error(msg)
        }
    }
    //限重设置的取消回调
    const handleCancel = () => {
        handleCallBack()
        form.resetFields()
    }

    return(
        <>
            <Modal
                width={useWindowFontSize(450)}
                title={"增加称重磅"}
                open={oneShow}
                onOk={handleOk}
                onCancel={handleCancel}
                getContainer={false}
            >
                <Form form={form}
                    labelCol={{ span: 8 }}
                    wrapperCol={{ span: 16 }}
                    labelAlign="left"
                >
                    <Form.Item
                        label="名称"
                        name="poundName"
                        rules={[{ required: true, message: "请填写称重磅名称!" }]}
                    >
                        <Input
                            placeholder="请填写称重磅名称"
                        />
                    </Form.Item>
                </Form>
            </Modal>
        </>
    )
}
export default AddWeight